package com.mes.biz.service.impl;

import com.github.pagehelper.PageInfo;
import com.mes.biz.domain.*;
import com.mes.biz.mapper.BizCustomerMapper;
import com.mes.biz.mapper.BizOrderMapper;
import com.mes.biz.mapper.BizProjectMapper;
import com.mes.biz.service.*;
import com.mes.common.core.domain.BaseEntity;
import com.mes.common.core.domain.entity.SysDept;
import com.mes.common.core.domain.entity.SysUser;
import com.mes.common.core.service.BaseServiceImpl;
import com.mes.common.utils.SecurityUtils;
import com.mes.common.utils.StringUtils;
import com.mes.framework.cache.DeptUtils;
import com.mes.framework.cache.UserUtils;
import com.mes.system.strategy.AutoCodeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Random;

/**
 * 项目Service业务层处理
 * @author hwg
 * @email hwg
 * @date 2023-05-15
 */
@Service
@Transactional(readOnly = true)
public class BizProjectServiceImpl extends BaseServiceImpl<BizProjectMapper, BizProject> implements BizProjectService {

    @Resource
    private BizProjectMapper bizProjectMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean createProject(BizProject bizProject) {
        Random random = new Random();
        //把随机生成的数字转成字符串
        String str = String.valueOf(random.nextInt(9));
        for (int i = 0; i < 5; i++) {
            str += random.nextInt(9);
        }
        bizProject.setProjectNumber("CGD-" + str);
        String tenantId = SecurityUtils.getTenantId();
        bizProject.setTenantId(tenantId);
        return save(bizProject);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateProject(BizProject bizProject) {
        int update = bizProjectMapper.update(bizProject);
        if(update > 0) {
            return true;
        }
        return false;
    }
}
